﻿using System;

namespace HaSdkWrapper
{
    static class Extensions
    {
        public static string TrimZeroChar(this string s)
        {
            return s.Replace("\0", "");
        }

        //convert epoch to datetime
        //public static DateTime ToDateTime(this uint unixTimestamp)
        //{

        //    // Convert the Unix timestamp to a DateTimeOffset object.
        //    DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(unixTimestamp);

        //    // Get the DateTime from the DateTimeOffset object.
        //    return dateTimeOffset.DateTime;

        //}
        public static DateTime ToDateTime(this uint unixTimestamp)
        {
            // 1970-01-01 00:00:00 UTC
            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            // 直接加秒数即可
            return epoch.AddSeconds(unixTimestamp);
        }
    }
}
